package cn.doublefloat.crm.project.customer.service.impl;

import cn.doublefloat.crm.project.customer.domain.Customer;

import cn.doublefloat.crm.project.customer.domain.Pie;
import cn.doublefloat.crm.project.customer.mapper.CustomerMapper;
import cn.doublefloat.crm.project.customer.mapper.DrainsMapper;
import cn.doublefloat.crm.project.customer.service.CustomerService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


/**
 * 实现层
 *
 * @author 蒲万徐
 */

@Service
public class CustomerServiceImpl implements CustomerService {
    @Resource
    private CustomerMapper customerMapper;
    @Resource
    private DrainsMapper drainsMapper;
    /**
     * 1.查询
     * @return
     */
    @Override
    public List<Customer> findCustomer() {
        List<Customer> list = customerMapper.findCustomer();
        return list;

    }

    /**
     * 添加
     *
     * @param customer 信息
     * @return 结果
     */
    @Override
    public int addCustomer(Customer customer) {
        int res = customerMapper.addCustomer(customer);
        return res;
    }

    /**
     * 3.修改
     *
     * @param customer
     */
    @Override
    public int updateCustomer(Customer customer) {
        int res = customerMapper.updateCustomer(customer);
        return res;
    }

    /**
     * 4.删除
     *
     * @param id
     */
    @Override
    public int deleteCustomer(int id) {
        int res = customerMapper.deleteCustomer(id);
        return res;
    }

    /**
     * 5.设置状态
     */
    @Override
    public int setCusState(Customer customer) {
        int res = customerMapper.setCusState(customer);
        drainsMapper.insertCustomer(customer.getId());
        return res;
    }

    @Override
    public Customer findById(int id) {
        return customerMapper.findById(id);
    }

    @Override
    public List<Pie> getPieData() {
        return customerMapper.getPieData();
    }

}
